package com.technoorbit.vbreakup;


import java.util.ArrayList;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;


public class ListItemsActivity extends BaseActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listitems);
        SetListAdapter();
   }
   
    public void SetListAdapter()
    { 
    	try {
    	Bundle extras = getIntent().getExtras();
    	String parentID = extras.getString("PARENTID");
    	String Type = extras.getString("TYPE");
		
    	
		final ArrayList<CustomList> listAdapter=JSONfunctions.ParseJsonMapData(String.format(URLOptions.str_CategoryURL,parentID),Type);
		
		if	(listAdapter!=null){
		Context ctx = getApplicationContext();
		Resources res = ctx.getResources();
		final ListView list;
		
		TypedArray icons = res.obtainTypedArray(R.array.arrow_icon);
		list=(ListView)findViewById(R.id.listItems);
		list.setAdapter(new CustomListAddapter(ctx, R.layout.categories,listAdapter, icons));
		
		list.setOnItemClickListener(new OnItemClickListener()
     	{
     	public void onItemClick(AdapterView<?> arg0, View v, int position, long id)
     	{
        	//String parentIDOnList=(String) list.getItemAtPosition(position);
     		int id1=listAdapter.get(position).getID();
        	StartCategoryListActivity(Integer.toString(id1));
     	 }
     
     	});
		}
		else{
			Intent intent=new Intent(ListItemsActivity.this, AdviceDetailActivity.class);
			intent.putExtra("PARENTID", parentID);
			intent.putExtra("TYPE", "Records");
			startActivity(intent);
			}
    	}
    	catch (Exception e) {
    		e.printStackTrace();
        
    	}
    }
    
    public void StartCategoryListActivity(String parentID) {
    	Intent intent=new Intent(ListItemsActivity.this, ListItemsActivity.class);
		intent.putExtra("PARENTID", parentID);
		intent.putExtra("TYPE", "Records");
		startActivity(intent);
	}
    
   
    		  
}